home *** CD-ROM | disk | FTP | other *** search
- le>
-
- <input type="submit" name="submit" value="Convert Temperature">
-
- </cfform>
-
- </cfmodule><!---
- **
- * CFMX Example Applications
- *
- * Copyright (c) 2002 Macromedia. All Rights Reserved.
- *
- * YOUR RIGHTS WITH RESPECT TO THIS SOFTWARE IS GOVERNED BY THE
- * TERMS AND CONDITIONS SET FORTH IN THE CORRESPONDING EULA.
- *
- **
- --->
-
- <cfmodule template="../tags/layout.cfm" pageName="Custom Tags Example - Page Source">
-
- <cfset variables.files = "index.cfm,tempconverter.cfm">
-
- <cfinclude template="../tags/showsource.cfm">
-
- </cfmodule>
-
- <!---
- **
- * CFMX Example Applications
- *
- * Copyright (c) 2002 Macromedia. All Rights Reserved.
- *
- * YOUR RIGHTS WITH RESPECT TO THIS SOFTWARE IS GOVERNED BY THE
- * TERMS AND CONDITIONS SET FORTH IN THE CORRESPONDING EULA.
- *
- **
- --->
-
- <!---
- Require Attributes.Temperature
- The attributes scope is a special scope for custom tags. It
- contains any data passed to the custom tag.
- --->
- <cfif not isDefined("attributes.temperature") or not IsNumeric(attributes.temperature)>
- <!--- Display an error message for the user. --->
- <cfoutput>
- <p>
- <b>TempConverter Error:</b> You must pass the "Temperature" attribute. This value must be a number.
- </p>
- </cfoutput>
- <cfabort>
- </cfif>
-
- <!---
- Require scale. This tell us what we are converting FROM.
- Valid values are:
- F or Fahrenheit
- C or Celsius
- --->
- <cfif not isDefined("attributes.scale") or not listFindNoCase("f,fahrenheit,c,celsius",attributes.scale)>
- <!--- Display an error message for the user. --->
- <cfoutput>
- <p>
- <b>TempConverter Error:</b> You must pass the "Scale" attribute. This value must be one of the following: F,Fahrenheit,C,Celsius.
- </p>
- </cfoutput>
- <cfabort>
- </cfif>
-
- <!---
- This custom tag needs to return it's value to the calling template.
- It allows the user to specify what the name of the returned value is.
- If the user doesn't specify the variable name, we default to 'temperature'.
- We use CFPARAM to default this, as well as to check for a valid variable name
- if the use passes one in.
- --->
- <cfparam name="attributes.returnVariable" default="temperature" type="variablename">
-
- <cfswitch expression="#attributes.scale#">
-
- <cfcase value="F,Fahrenheit">
- <cfset returnVal = (attributes.temperature-32.0) * (5.0/9.0)>
- </cfcase>
-
- <cfcase value="C,Celsius">
- <cfset returnVal = (attributes.temperature * 9.0/5.0) + 32>
- </cfcase>
-
- </cfswitch>
-
- <!---
- We now return the value to the user. We use the setVariable function
- to write to the caller scope, which is the local scope of the template
- that called us.
- --->
-
- <cfset setVariable("Caller.#attributes.returnVariable#",returnVal)><!---
- **
- * CFMX Example Applications
- *
- * Copyright (c) 2002 Macromedia. All Rights Reserved.
- *
- * YOUR RIGHTS WITH RESPECT TO THIS SOFTWARE IS GOVERNED BY THE
- * TERMS AND CONDITIONS SET FORTH IN THE CORRESPOND